<?php
//decode by QQ:735674691 http://bbs.yaoduoli.com/

if (!defined('INDEX')) {
    exit('Access Denied');
}
function act_huan_list($pagesize=10,$field='id,img,jifen,jifenbao,title,num,sdate,edate'){
	global $duoduo;
	$webset=$duoduo->webset;
	$dduser=$duoduo->dduser;
	$cid=(int)$_GET['cid'];
	$page = !($_GET['page'])?'1':intval($_GET['page']);
	$frmnum=($page-1)*$pagesize;
	
	$jifenbao_huan_goods=0;
	if(JIFENBAO==2 && $cid==0){
		if($page==1){
			$pagesize=11;
			$jifenbao_huan_goods=1;
		}
		else{
			$frmnum--;
		}
	}
	
	if($cid>0){
		$where=' and cid="'.$cid.'"';
	}
	else{
		$where='';
	}
	
	//类型
	$type_all=dd_get_cache('type');
	$huan_type=$type_all['huan_goods'];
	foreach($huan_type as $k=>$v){
		$huan_type_arr[$k]['url']=wap_l('huan','index',array('cid'=>$k));
		$huan_type_arr[$k]['title']=$v;
	}
	$total=$duoduo->count('huan_goods',"hide='0' and num>0 and del=0 and (edate=0 or edate>'".TIME."')".$where);
	$huan=$duoduo->select_all('huan_goods',$field, "hide='0' and num>0 and del=0 and (edate=0 or edate>'".TIME."') and (sdate=0 or sdate<'".TIME."') ".$where." order by sort=0 asc,sort asc,id desc limit $frmnum,$pagesize");
	foreach($huan as $k=>$row){
		$huan[$k]['url']=wap_l('huan','view',array('id'=>$row["id"]));
	}
	$page_url=wap_l(MOD,ACT,array('cid'=>$cid));
	unset($duoduo);
	$parameter['cid']=$cid;
	$parameter['huan_type']=$huan_type;
	$parameter['huan_type_arr']=$huan_type_arr;
	$parameter['total']=$total;
	$parameter['huan']=$huan;
	$parameter['page_url']=$page_url;
	$parameter['jifenbao_huan_goods']=$jifenbao_huan_goods;
	$parameter['pagesize']=$pagesize;
	$parameter['tixian_jifenbao']=u('user','tixian',array('type'=>1,'from'=>'huan'));
	$parameter['info_jifenbao']=u('tao','jifenbao');
	$parameter['pageurl']=pageft($total,$pagesize,$page_url,WJT);
	return $parameter;
}